﻿using System;
using System.Collections.Generic;

namespace CompositeDesignPattern
{
    public class DocumentChapter : DocumentElement
    {
        private int chapterNumber;
        private IList<DocumentElement> children = new List<DocumentElement>();

        public DocumentChapter(int number)
        {
            this.chapterNumber = number;
        }

        public override void Add(DocumentElement child)
        {
            children.Add(child);
        }

        public override void Remove(DocumentElement child)
        {
            children.Remove(child);
        }

        public override void Write()
        {
            Console.WriteLine("Chapter {0}", chapterNumber);
            foreach (DocumentElement element in children)
            {
                element.Write();
            }
        }
    }
}
